<!doctype html>
<html lang="en">
<!--[if IE 9 ]>
<html  lang="en" class="ie9">
<![endif]-->
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
    <meta name="format-detection" content="telephone=no">
    <meta charset="UTF-8">
    <title>用户管理</title>
    <!-- CSS -->
    <link  rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="css/animate.min.css">
    <link rel="stylesheet" href="css/font-awesome.min.css">
    <link rel="stylesheet" href="css/form.css">
    <link rel="stylesheet" href="css/style.css">
    <link rel="stylesheet" href="css/icons.css">
    <link rel="stylesheet" href="css/generics.css">
    <link rel="stylesheet" href="css/bstable/bootstrap-table.css">
    <link rel="stylesheet" href="css/bstable/bootstrap-table-self.css">
    <style>
        .cursor{
            cursor: pointer;
        }
    </style>
</head>
<body id="skin-blur-blue">
<header id="header" class="media">
    <a href="" id="menu-toggle"></a>
    <a class="logo pull-left" href="index.html">
        <img src="images/logo.png" alt="logo">
    </a>
    <div class="media-body">
        <div class="media" id="top-menu">
            <div class="pull-left tm-icon">
                <a data-drawer="messages" class="drawer-toggle" href="">
                    <i class="sa-top-message"></i>
                    <span>时间回溯</span>
                </a>
            </div>
            <div class="pull-left tm-icon">
                <a data-drawer="notifications" class="drawer-toggle" href="">
                    <i class="sa-top-updates"></i>
                    <span>帮助</span>
                </a>
            </div>
            <div id="time" class="pull-right">
                <span id="hours"></span>
                :
                <span id="min"></span>
                :
                <span id="sec"></span>
            </div>
            <div class="media-body">
                <input type="text" class="main-search">
            </div>
        </div>
    </div>
</header>
<div class="clearfix"></div>
<section id="main" class="p-relative" role="main">
    <!-- Sidebar -->
    <aside id="sidebar">
        <!-- Side Menu -->
        <ul class="list-unstyled side-menu">
            <li>
                <a class="sa-side-home" href="index.html">
                    <span class="menu-item">首页</span>
                </a>
            </li>
            <li>
                <a class="sa-side-typography" href="settingindex.html">
                    <span class="menu-item">系统管理</span>
                </a>
            </li>
            <li class="active">
                <a class="sa-side-widget" href="settingindex2.html">
                    <span class="menu-item">用户管理</span>
                </a>
            </li>
            <li>
                <a class="sa-side-table" href="settingindex3.html">
                    <span class="menu-item">产品配置与管理</span>
                </a>
            </li>
            <li>
                <a class="sa-side-form" href="settingindex4.html">
                    <span class="menu-item">常用工具管理</span>
                </a>
            </li>
        </ul>
    </aside>
    <!-- Content -->
    <section id="content" class="container">
        <!-- Messages Drawer时间回溯 -->
        <div id="messages" class="tile drawer animated">
            <div class="listview narrow">
                <div class="media">
                    <a href="">时间回溯</a>
                    <span class="drawer-close">&times;</span>
                </div>
                <div class="overflow" style="height: 254px">
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/1.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Nadin Jackson - 2 Hours ago</small><br>
                            <a class="t-overflow" href="">Mauris consectetur urna nec tempor adipiscing. Proin sit amet nisi ligula. Sed eu adipiscing lectus</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/2.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">David Villa - 5 Hours ago</small><br>
                            <a class="t-overflow" href="">Suspendisse in purus ut nibh placerat Cras pulvinar euismod nunc quis gravida. Suspendisse pharetra</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/3.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Harris worgon - On 15/12/2013</small><br>
                            <a class="t-overflow" href="">Maecenas venenatis enim condimentum ultrices fringilla. Nulla eget libero rhoncus, bibendum diam eleifend, vulputate mi. Fusce non nibh pulvinar, ornare turpis id</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/4.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Mitch Bradberry - On 14/12/2013</small><br>
                            <a class="t-overflow" href="">Phasellus interdum felis enim, eu bibendum ipsum tristique vitae. Phasellus feugiat massa orci, sed viverra felis aliquet quis. Curabitur vel blandit odio. Vestibulum sagittis quis sem sit amet tristique.</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/1.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Nadin Jackson - On 15/12/2013</small><br>
                            <a class="t-overflow" href="">Ipsum wintoo consectetur urna nec tempor adipiscing. Proin sit amet nisi ligula. Sed eu adipiscing lectus</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/2.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">David Villa - On 16/12/2013</small><br>
                            <a class="t-overflow" href="">Suspendisse in purus ut nibh placerat Cras pulvinar euismod nunc quis gravida. Suspendisse pharetra</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/3.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Harris worgon - On 17/12/2013</small><br>
                            <a class="t-overflow" href="">Maecenas venenatis enim condimentum ultrices fringilla. Nulla eget libero rhoncus, bibendum diam eleifend, vulputate mi. Fusce non nibh pulvinar, ornare turpis id</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/4.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Mitch Bradberry - On 18/12/2013</small><br>
                            <a class="t-overflow" href="">Phasellus interdum felis enim, eu bibendum ipsum tristique vitae. Phasellus feugiat massa orci, sed viverra felis aliquet quis. Curabitur vel blandit odio. Vestibulum sagittis quis sem sit amet tristique.</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/5.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Wendy Mitchell - On 19/12/2013</small><br>
                            <a class="t-overflow" href="">Integer a eros dapibus, vehicula quam accumsan, tincidunt purus</a>
                        </div>
                    </div>
                </div>
                <div class="media text-center whiter l-100">
                    <a href=""><small>VIEW ALL</small></a>
                </div>
            </div>
        </div>
        <!-- Notification Drawer帮助 -->
        <div id="notifications" class="tile drawer animated">
            <div class="listview narrow">
                <div class="media">
                    <a href="">帮助</a>
                    <span class="drawer-close">&times;</span>
                </div>
                <div class="overflow" style="height: 254px">
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/1.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Nadin Jackson - 2 Hours ago</small><br>
                            <a class="t-overflow" href="">Mauris consectetur urna nec tempor adipiscing. Proin sit amet nisi ligula. Sed eu adipiscing lectus</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/2.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">David Villa - 5 Hours ago</small><br>
                            <a class="t-overflow" href="">Suspendisse in purus ut nibh placerat Cras pulvinar euismod nunc quis gravida. Suspendisse pharetra</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/3.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Harris worgon - On 15/12/2013</small><br>
                            <a class="t-overflow" href="">Maecenas venenatis enim condimentum ultrices fringilla. Nulla eget libero rhoncus, bibendum diam eleifend, vulputate mi. Fusce non nibh pulvinar, ornare turpis id</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/4.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Mitch Bradberry - On 14/12/2013</small><br>
                            <a class="t-overflow" href="">Phasellus interdum felis enim, eu bibendum ipsum tristique vitae. Phasellus feugiat massa orci, sed viverra felis aliquet quis. Curabitur vel blandit odio. Vestibulum sagittis quis sem sit amet tristique.</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/1.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">Nadin Jackson - On 15/12/2013</small><br>
                            <a class="t-overflow" href="">Ipsum wintoo consectetur urna nec tempor adipiscing. Proin sit amet nisi ligula. Sed eu adipiscing lectus</a>
                        </div>
                    </div>
                    <div class="media">
                        <div class="pull-left">
                            <img width="40" src="img/profile-pics/2.jpg" alt="">
                        </div>
                        <div class="media-body">
                            <small class="text-muted">David Villa - On 16/12/2013</small><br>
                            <a class="t-overflow" href="">Suspendisse in purus ut nibh placerat Cras pulvinar euismod nunc quis gravida. Suspendisse pharetra</a>
                        </div>
                    </div>
                </div>
                <div class="media text-center whiter l-100">
                    <a href=""><small>VIEW ALL</small></a>
                </div>
            </div>
        </div>
        <!-- Breadcrumb -->
        <ol class="breadcrumb hidden-xs">
            <li><a href="settingindex4.html">常用工具管理</a></li>
            <li><a href="settingindex3.html">产品配置与管理</a></li>
            <li class="active">用户管理</li>
            <li><a href="settingindex.html">系统管理</a></li>
        </ol>
        <h4 class="page-title">用户管理页面</h4>
        <div class="block-area" id="tableStriped">
            <h3 class="block-title">账号管理</h3>
            <div class="table-responsive overflow">
                <div id="btnAddRemove">
                    <button class="btn btn-default" id="addtable4Row"  data-toggle="modal" data-target="#table-modal">
                        <span>新增</span>
                        <span class="glyphicon glyphicon-plus"></span>
                    </button>
                    <div class="modal fade in" id="table-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content" style="background: #000;">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                        &times;
                                    </button>
                                    <h4 class="modal-title">
                                        增加行
                                    </h4>
                                </div>
                                <div class="modal-body">
                                    <div class="form-horizontal">
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                    </button>
                                    <button type="button" class="btn btn-primary footer-btn" data-dismiss="modal" id="btn-addtableRow">
                                        提交更改
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                <!--    <button class="btn btn-default" id="deltable4Row">
                        <span>删除</span>
                        <span class="glyphicon glyphicon-remove"></span>
                    </button>-->
            <!--        <button class="btn btn-default" id="changetable4Row"  data-target="#changetableRow-modal">
                        <span>修改</span>
                        <span class="glyphicon glyphicon-pencil"></span>
                    </button>-->
                    <div class="modal fade in" id="changetableRow-modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content" style="background: #000;">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                        &times;
                                    </button>
                                    <h4 class="modal-title">
                                        更改行内容
                                    </h4>
                                </div>
                                <div class="modal-body">
                                    <div class="form-horizontal">
                                    </div>
                                </div>
                                <div class="modal-footer">
                                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                                    </button>
                                    <button type="button" class="btn btn-primary footer-btn" data-dismiss="modal" id="btn-changetableRow">
                                        提交更改
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <table id="table4"></table>
                <!--<table id="table4"-->
                       <!--data-toggle="table"-->
                       <!--data-url="json/sindex2.json"-->
                       <!--data-toolbar="#btnAddRemove"-->
                       <!--data-height="360"-->
                       <!--data-pagination=true-->
                       <!--data-show-columns=true-->
                <!--&gt;-->
                    <!--<tr>-->
                        <!--<th data-field="name" data-sortable="true">用户</th>-->
                        <!--<th data-field="enterTime" data-sortable="true">登录时间</th>-->
                        <!--<th data-field="outTime" data-sortable="true">登出时间</th>-->
                        <!--<th data-field="from" data-sortable="true">来源</th>-->
                        <!--<th data-field="doWhat" data-sortable="true">操作内容</th>-->
                        <!--<th data-events="operateEvents" data-formatter="operateFormatter">操作</th>-->
                    <!--</tr>-->
                <!--</table>-->
            </div>
        </div>
    </section>
    <!-- Older IE Message -->
    <!--[if lt IE 9]>
    <div class="ie-block">
        <h1 class="Ops">抱歉！</h1>
        <p>您正在使用一个过时的Internet Explorer版本，升级到以下任何Web浏览器，以便访问该网站的最大功能。 </p>
        <ul class="browsers">
            <li>
                <a href="http://www.google.cn/intl/zh-CN/chrome/browser/desktop/index.html">
                    <img src="img/browsers/chrome.png" alt="">
                    <div>Google Chrome</div>
                </a>
            </li>
            <li>
                <a href="http://www.firefox.com.cn/">
                    <img src="img/browsers/firefox.png" alt="">
                    <div>Mozilla Firefox</div>
                </a>
            </li>
            <li>
                <a href="http://www.oupeng.com/download">
                    <img src="img/browsers/opera.png" alt="">
                    <div>Opera</div>
                </a>
            </li>
            <li>
                <a href="https://www.apple.com/cn/safari/">
                    <img src="img/browsers/safari.png" alt="">
                    <div>Safari</div>
                </a>
            </li>
            <li>
                <a href="https://support.microsoft.com/zh-cn/help/17621/internet-explorer-downloads">
                    <img src="img/browsers/ie.png" alt="">
                    <div>Internet Explorer(New)</div>
                </a>
            </li>
        </ul>
        <p>升级你的浏览器更安全和更快的网络体验。 <br/>感谢你的支持...</p>
    </div>
    <![endif]-->
</section>
</body>
</html>
<!-- jQuery -->
<script src="js/jquery.min.js"></script>
<!-- Bootstrap -->
<script src="js/bootstrap.min.js"></script>
<!-- Bootstrap-table -->
<script src="js/bstable/bootstrap-table.js"></script>
<script src="js/bstable/bootstrap-table-zh-CN.js"></script>
<script src="js/functions.js"></script>
<script>
    $(function(){
        $("#table4").bootstrapTable({
            url:"json/sindex2.json",
            toolbar:"#btnAddRemove",
            height:"360",
            pagination:true,
            showColumns:true,
            columns:[
                {
                    title:"用户",
                    field:"name",
                    sortable:true
                },
                {
                    title:"登录时间",
                    field:"enterTime",
                    sortable:true
                },
                {
                    title:"登出时间",
                    field:"outTime",
                    sortable:true
                },
                {
                    title:"来源",
                    field:"from",
                    sortable:true
                },
                {
                    title:"操作内容",
                    field:"doWhat",
                    sortable:true
                },
                {
                    field: 'operate',
                    title:"操作",
                     events: operateEvents ,
                     formatter: operateFormatter
//                    formatter: function (value,row,index) {
//                        return [
//                            '<img src="images/edit.png"/ class="cursor edit" onclick="changeRow()"/>' +
//                            '<img src="images/false.png" style="padding-left: 5%;padding-right: 5%;" class="cursor imgDel remove" onclick="delRow(\''+row.id+'\')"/>'
//                        ].join('');
//                    }
                }
            ]
        });


                function operateFormatter (value, row, index){
                    return [
                        '<img src="images/edit.png"/ class="cursor edit"/>' +
                        '<img src="images/false.png" style="padding-left: 5%;padding-right: 5%;" class="cursor imgDel remove"/>'
                    ].join('');
                }



            window.operateEvents  = {
                'click .remove': function (e, value, row, index) {
                    $("#table4").bootstrapTable('remove', {
                        field: 'id',
                        values: id
                    });
                }
         };










        var field = ["name","enterTime","outTime","from","doWhat"];
        $("#deltable4Row").click(function(){
            var ids = $.map($("#table4").bootstrapTable('getSelections'), function (row) {
                return row.id;
            });
            $("#table4").bootstrapTable('remove', {
                field: 'id',
                values: ids
            });
        });
        $("#addtable4Row").click(function(){
            $("#table-modal>.modal-dialog>.modal-content>.modal-body>.form-horizontal").html("");
            var length = $("#table4").bootstrapTable()[0].firstChild.firstChild.children.length;
            for(var i=0;i<length-1;i++){
                var formGroup = $('<div class="form-group">'+
                        '<div class="col-md-9">'+
                        '<input type="text" class="form-control input-sm m-t-15 addtableRowInput">'+
                        '</div>'+
                        '</div>');
                var label = $('<lable class="col-md-2 control-label">'+
                        $("#table4").bootstrapTable()[0].firstChild.firstChild.children[i].innerText+
                        ':</lable>');
                $(formGroup).prepend(label);
                $("#table-modal>.modal-dialog>.modal-content>.modal-body>.form-horizontal").append(formGroup);
            }
        });
        $("#btn-addtableRow").click(function(){
            var rowVal = {};
            rowVal.id = $("#table4").bootstrapTable('getData').length;//id应该有bug没有考虑到用户删除的情况
            for(var i=0;i<$(".addtableRowInput").length;i++){
                rowVal[field[i]] = $(".addtableRowInput").eq(i).val();
            }
            $("#table4").bootstrapTable('insertRow', {
                index: 0,
                row:rowVal
            });
        });
        $("#changetable4Row").click(function(){
            if($("#table4").bootstrapTable('getSelections')[0]){
                if($("#table4").bootstrapTable('getSelections').length == 1){
                    $("#changetableRow-modal>.modal-dialog>.modal-content>.modal-body>.form-horizontal").html("");

//                    console.log($("#table4").bootstrapTable('getRowByUniqueId', 1));//此参数老是报错未找到原因
//                    console.log($("#table4").bootstrapTable('getData').length);//可用来做ID
                    var InputVal = [];
//                    InputVal.push($("#table4").bootstrapTable("getSelections")[0]["id"]);
                    InputVal.push($("#table4").bootstrapTable("getSelections")[0]["name"]);
                    InputVal.push($("#table4").bootstrapTable("getSelections")[0]["enterTime"]);
                    InputVal.push($("#table4").bootstrapTable("getSelections")[0]["outTime"]);
                    InputVal.push($("#table4").bootstrapTable("getSelections")[0]["from"]);
                    InputVal.push($("#table4").bootstrapTable("getSelections")[0]["doWhat"]);

                    var length = $("#table4").bootstrapTable()[0].firstChild.firstChild.children.length;
                    for(var i=0;i<length;i++){
                        if(i){
                            var formGroup = $('<div class="form-group">'+
                                    '<div class="col-md-9">'+
                                    '<input type="text" class="form-control input-sm m-t-15 changetableRowInput" value="'+InputVal[i-1]+'" >'+
                                    '</div>'+
                                    '</div>');
                            var label = $('<lable class="col-md-2 control-label">'+
                                    $("#table4").bootstrapTable()[0].firstChild.firstChild.children[i].innerText+
                                    ':</lable>');
                            $(formGroup).prepend(label);
                            $("#changetableRow-modal>.modal-dialog>.modal-content>.modal-body>.form-horizontal").append(formGroup);
                        }
                    }
                    $('#changetableRow-modal').modal('show');
                }
            }
        });
        $("#btn-changetableRow").click(function(){
            var rowValue = {};
            for(var i=0;i<$(".changetableRowInput").length;i++){
                rowValue[field[i]] = $(".changetableRowInput").eq(i).val()
            }
            $("#table4").bootstrapTable("updateRow",{
                index:$("#table4 .selected").attr("data-index"),
                row:rowValue
            });
        });
        $('button[data-toggle="dropdown"]').click(function(){
            if($(this).parent().hasClass("open")){
                //如果这个CLASS存在则返回给后台
                console.log($(this).siblings(".dropdown-menu").find('input[value="0"]').attr("checked"));
            }else {
                $(this).siblings(".dropdown-menu").find('input[value="0"]').click();
            }
        });
    });


    window.operateEvents  = {
        'click .remove': function (e, value, row, index) {
            $("#table4").bootstrapTable('remove', {
                field: 'id',
                values: row.id
            });
        },
        'click .edit':function(){
            $("#changetableRow-modal>.modal-dialog>.modal-content>.modal-body>.form-horizontal").html("");

//                    console.log($("#table4").bootstrapTable('getRowByUniqueId', 1));//此参数老是报错未找到原因
//                    console.log($("#table4").bootstrapTable('getData').length);//可用来做ID

            console.log($("#table4").bootstrapTable('getRowByUniqueId', 1));
            console.log($("#table4").bootstrapTable("getSelections"));
            var InputVal = [];
//                    InputVal.push($("#table4").bootstrapTable("getSelections")[0]["id"]);
            InputVal.push($("#table4").bootstrapTable("getSelections")[0]["name"]);
            InputVal.push($("#table4").bootstrapTable("getSelections")[0]["enterTime"]);
            InputVal.push($("#table4").bootstrapTable("getSelections")[0]["outTime"]);
            InputVal.push($("#table4").bootstrapTable("getSelections")[0]["from"]);
            InputVal.push($("#table4").bootstrapTable("getSelections")[0]["doWhat"]);

            var length = $("#table4").bootstrapTable()[0].firstChild.firstChild.children.length;
            for(var i=0;i<length;i++){
                if(i){
                    var formGroup = $('<div class="form-group">'+
                            '<div class="col-md-9">'+
                            '<input type="text" class="form-control input-sm m-t-15 changetableRowInput" value="'+InputVal[i-1]+'" >'+
                            '</div>'+
                            '</div>');
                    var label = $('<lable class="col-md-2 control-label">'+
                            $("#table4").bootstrapTable()[0].firstChild.firstChild.children[i].innerText+
                            ':</lable>');
                    $(formGroup).prepend(label);
                    $("#changetableRow-modal>.modal-dialog>.modal-content>.modal-body>.form-horizontal").append(formGroup);
                }
            }
            $('#changetableRow-modal').modal('show');
        }
    }

</script>
